#![feature(mpmc_channel)]
#![warn(clippy::all, rust_2018_idioms)]
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release

pub(crate) mod ui;
pub(crate) mod services;
pub(crate) mod utils;
pub(crate) mod weidget;
pub(crate) mod laudio;

use std::sync::Arc;
use env_logger;

use eframe;
use egui::IconData;
use image;



pub(crate) const MAIN_WIDTH: f32 = 1280.0;
pub(crate) const MAIN_HEIGHT: f32 = 720.0;

// #[tokio::main]
// async fn main(){
//     let edit_str001 = "[12,12,12,12,12,12]";
//     let rs:Vec<u8> =  serde_json::from_str(edit_str001).unwrap_or_default();
//     println!("rs: {:?}", rs);
// }

#[tokio::main]
async fn main() -> eframe::Result {
    env_logger::init();
    
    let options = eframe::NativeOptions {
        viewport: egui::ViewportBuilder::default()
            .with_inner_size([MAIN_WIDTH, MAIN_HEIGHT])
            .with_icon(trans_icon()),
        ..Default::default()
    };
   
    eframe::run_native(
        "聊天工具",
        options,
        Box::new(|cc| {
            // This gives us image support:
            egui_extras::install_image_loaders(&cc.egui_ctx);

            Ok(Box::<ui::MyApp>::new(ui::MyApp::new(cc)))
        }),
    )

}

// Demonstrates how to replace all fonts.
fn replace_fonts(ctx: &egui::Context) {
    // Start with the default fonts (we will be adding to them rather than replacing them).
    let mut fonts = egui::FontDefinitions::default();

    // Install my own font (maybe supporting non-latin characters).
    // .ttf and .otf files supported.
    fonts.font_data.insert(
        "my_font".to_owned(),
        Arc::from(egui::FontData::from_static(include_bytes!(
            "../res/font/STSong-Light.ttf"
        ))),
    );

    // Put my font first (highest priority) for proportional text:
    fonts
        .families
        .entry(egui::FontFamily::Proportional)
        .or_default()
        .insert(0, "my_font".to_owned());

    // Put my font as last fallback for monospace:
    fonts
        .families
        .entry(egui::FontFamily::Monospace)
        .or_default()
        .push("my_font".to_owned());

    // Tell egui to use these fonts:
    ctx.set_fonts(fonts);
}


pub(crate) fn trans_icon() -> Arc<IconData> {
    let logo_png = include_bytes!("../res/image/logo.png");
    let icon_img = image::load_from_memory(logo_png).unwrap();
    let icon_rgba = icon_img.into_rgba8();

    let (width, height) = icon_rgba.dimensions();
    Arc::new(IconData {
        rgba: icon_rgba.into_raw(),
        width,
        height,
    })
}










